export const propPath = (rec, propPath) => {

  if (!propPath.includes('.')) {

    return rec[propPath];

  } else {

    const path = propPath.split('.').reverse();

    let curr = rec;
    while(curr && path.length > 0) {
      curr = curr?.[path.pop()];
    }
  
    return curr;
  }

}

export const propFunc = (rec, propSpec='') => {

  if (typeof propSpec === 'function') {

    return propSpec(rec);

  } else if (typeof propSpec === 'string') {

    return propPath(rec, propSpec);

  } else {
    
    return undefined;

  }
}
